from vanna.exceptions import ValidationError

# 定义一个拦截器函数来检查SQL语句，以支持read-only
def intercept_sql(statement):
    # List of SQL keywords that indicate a write operation
    write_operations = (
        "insert",
        "update",
        "delete",
        "create",
        "drop",
        "alter",
        "truncate",
        "rename",
    )
    # Check if the statement starts with any of the write operation keywords
    if any(statement.strip().lower().startswith(op) for op in write_operations):
        raise ValidationError(
            "Database is read-only. Write operations are not allowed."
        )
